package com.example.mvc.mapper;


import com.example.mvc.bean.Book;
import com.example.mvc.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {


    /**
     * 根据用户名和密码查询用户对象
     * @param username
     * @param password
     * @return
     */
    @Select("select * from admin where username = #{username} and password = #{password}")
    User select(@Param("username") String username, @Param("password")  String password);

    /**
     * 根据用户名查询用户对象
     * @param username
     * @return
     */
    @Select("select * from admin where username = #{username}")
    User selectByUsername(String username);

    /**
     * 添加用户
     * @param user
     */
    @Insert("INSERT INTO admin(username,name,password,email,phone,lend_num,max_num) VALUE(#{username},#{name},#{password},#{email},#{phone},#{lend_num},#{max_num})")
    void add(User user);


    @Select("SELECT * FROM admin")
    List<User> getUserList();

    //添加读者
    @Insert("INSERT INTO admin(username,name,password,email,phone,lend_num,max_num) VALUE(#{username},#{name},#{password},#{email},#{phone},#{lend_num},#{max_num})")
    int addReadUser(User user);

    //修改用户
    @Update("UPDATE admin SET username=#{username},name=#{name},email=#{email},phone=#{phone},password=#{password},lend_num=#{lend_num},max_num=#{max_num} WHERE aid=#{aid}")
    int updateReadUser(User book);

    //删除
    @Delete("DELETE FROM admin WHERE aid=#{aid}")
    int deleteReadUserById(int aid);


    /**
     * 根据用户id查询用户对象
     * @param userId
     * @return
     */
    @Select("select * from admin where aid = #{userId}")
    User getUserById(Integer  userId);

}
